import struct, os

import DataExtraction.BSAHeader

class BSAHeaderDFA(DataExtraction.BSAHeader.BSAHeader):
    def __init__(self, width = 0, height = 0, frame_count = 0, u2 = 0,
                 u3 = 0, compressed_size = 0):
        DataExtraction.BSAHeader.BSAHeader.__init__(self, width, height)
        self._frame_count = frame_count
        self._u2 = u2
        self._u3 = u3
        self._compressed_size = compressed_size
        
        # 6 WORD's
        self._unpack_fmt = 6 * 'H'
        self._size_in_bytes = struct.calcsize(self._unpack_fmt)
        
    def __repr__(self):
        return "BSAHeaderDFA: [width=" + str(self.get_width()) + "|height=" +\
            str(self.get_height()) + "|frame_count=" + str(self._frame_count) +\
            "|u2=" + str(self._u2) + "|u3=" + str(self._u3) + "|compressed_size=" +\
            str(self._compressed_size) + "]"
    
    # getters
    def get_frame_count(self):
        return self._frame_count
    
    def get_u2(self):
        return self._u2
    
    def get_u3(self):
        return self._u3
    
    def get_compressed_size(self):
        return self._compressed_size
    
    def get_size_in_bytes(self):
        return self._size_in_bytes
    
    # setters
    def set_frame_count(self, frame_count):
        self._frame_count = frame_count
        
    def set_u2(self, u2):
        self._u2 = u2
        
    def set_u3(self, u3):
        self._u3 = u3
    
    def set_compressed_size(self, compressed_size):
        self._compressed_size = compressed_size
        
    def load(self, global_bsa_data, start):
        curr_offset = global_bsa_data.tell()
        
        global_bsa_data.seek(start, os.SEEK_SET)
        
        r = global_bsa_data.read(self._size_in_bytes)
        
        self._frame_count, self._u2, self._u3, self._width, self._height,\
            self._compressed_size = struct.unpack(self._unpack_fmt, r)
        
        global_bsa_data.seek(curr_offset, os.SEEK_SET)